{% extends 'base/base.html' %}
{% block title %}
    {{ page_title }}
{% endblock %}

{% block main %}



    <div class="container mt-4">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <h3>{{ page_title }}</h3>
                        <p class="text-muted">共找到 {{ files.count }} 个文件</p>
                    </div>
                    <div class="card-body">
                        {% if files %}
                            <div class="list-group">
                                {% for file in files %}
                                    <div style="word-break: break-word; overflow-wrap: break-word;max-width: 100%;
                                        " class="list-group-item">
                                        <div class="d-flex w-100 justify-content-between">
                                            <h5 class="mb-1">
                                                <a href="{% url 'main:files_detail' file.id %}?back={{ request.get_full_path|urlencode }}"
                                                   class="text-decoration-none">
                                                    {{ file.title }}
                                                </a>
                                            </h5>
                                            <small class="text-muted">{{ file.create_time|date:"Y-m-d H:i" }}</small>
                                        </div>
                                        <p class="mb-1">{{ file.content|striptags|truncatechars:150 }}</p>
                                        <div class="mt-2">
                                            <small class="text-muted">
                                                <strong>作者:</strong> {{ file.author.username }} |

                                                <strong>标签:</strong>
                                                {% for tag in file.tags.all %}
                                                    <span class="badge bg-secondary">{{ tag.title }}  </span>
                                                {% endfor %}
                                                <span> | </span>
                                                {% if request.user.is_superuser or request.user.username == file.author.username %}
                                                    <strong>状态:</strong>
                                                    <span class="badge
                                                           {% if file.state == 'success' %}alert-success
                                                            {% elif file.state == 'fail' %}alert-danger
                                                            {% else %}badge-warning{% endif %}">
                                                        {{ file.get_state_display }}

                                                    </span>
                                                {% endif %}
                                            </small>
                                        </div>
                                    </div>
                                {% endfor %}
                            </div>
                        {% else %}
                            <div class="text-center py-4">
                                <i class="fas fa-folder-open fa-3x text-muted mb-3"></i>
                                <p class="text-muted">暂无相关文件</p>
                                <a href="{% url 'main:index' %}" class="btn btn-primary">返回首页</a>
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}